
local mt = ac.skill['弹射攻击']
mt.art = [[ReplaceableTextures\PassiveButtons\PASBTNUpgradeMoonGlaive.blp]]
mt.missile_art = [[Abilities\Weapons\SentinelMissile\SentinelMissile.mdl]]
mt.missile_speed = 900
mt.MissileArc = 0.1
mt.damage_count = 2
mt.damage = 100
mt.damage_loss = 0.5

function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        local cast = self:create_cast()
        cast.damage = hero:get('攻击')
        cast:notify('shot_missil',hero,target)
    end))
end



--弹射伤害
function mt:shot_missil(hero,dest)
    self.gourp = self.gourp or {}
    self.gourp[dest] = true
    local point = dest:get_point()
    local target = ac.selector('unit'):range(dest,600):is_not(dest):enemy(hero):sorter(function(a,b)
        if self.gourp[a] and self.gourp[b]==nil then
            return false
        end
        if self.gourp[a]==nil and self.gourp[b] then
            return true
        end
		local r1 = a:get_point() * point
		local r2 = b:get_point() * point
		return r1 < r2
    end):first()
    if target then
        local start = dest:get_launch_point()
        start:launch_missile(target,self.missile_art,self.missile_speed,self.MissileArc,function()
            self:notify('on_hit',hero,target)
            self.damage = self.damage * (1 - self.damage_loss)
            self.damage_count = self.damage_count - 1
            if self.damage_count>0 then
                self:shot_missil(hero,target)
            end
        end)
        
    end
end


--造成伤害
function mt:on_hit(hero,target)
    hero:create_damage(target,self.damage,'物理')
end
